package IOperate;

import book.*;

import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
public class AddBook implements Ioperate{
    @Override
    public void work(BookList bookList) {
        int count = bookList.size;

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入增加的书名：");
        String name = scanner.nextLine();
        System.out.println("请输入增加的书名的作者：");
        String author = scanner.nextLine();
        System.out.println("请输入书的价格：");
        int price = scanner.nextInt();
        String x = scanner.nextLine();
        System.out.println("请输入属的类型：");
        String type = scanner.nextLine();

        Book book = new Book(name,author,price,type);
        for (int i = 0; i < count; i++) {
            if(name.equals(bookList.getBooks(i).getName())){
                System.out.println("此书已存在");
                return ;
            }
        }

        bookList.setBooks(bookList.size,book);
        bookList.size++;
        System.out.println("添加成功！");
        System.out.println();
    }
}
